package controllers

/*
厦门大学计算机专业 | 前华为工程师
专注《零基础学编程系列》  http://lblbc.cn/blog
包含：Java | 安卓 | 前端 | Flutter | iOS | 小程序 | 鸿蒙
公众号：蓝不蓝编程
*/
import (
	"net/http"

	"github.com/gin-gonic/gin"
	"lblbc.cn/demo/entity"
	"lblbc.cn/demo/helper"
	"lblbc.cn/demo/services"
)

type GoodsController interface {
	QueryGoodsByCategory(c *gin.Context, categoryId string)
	QueryGoods(c *gin.Context, goodsId string)
	SearchGoods(c *gin.Context, keyword string)
}

type goodsController struct {
	goodsService services.GoodsService
}

func NewGoodsController(goodsService services.GoodsService) GoodsController {
	return &goodsController{goodsService: goodsService}
}

func (c *goodsController) QueryGoodsByCategory(ctx *gin.Context, categoryId string) {
	var result []entity.Goods = c.goodsService.QueryGoodsByCategory(categoryId)
	response := helper.SuccessResponse(0, "", result)
	ctx.JSON(http.StatusOK, response)
}

func (c *goodsController) QueryGoods(ctx *gin.Context, goodsId string) {
	var result entity.Goods = c.goodsService.QueryGoods(goodsId)
	response := helper.SuccessResponse(0, "", result)
	ctx.JSON(http.StatusOK, response)
}

func (c *goodsController) SearchGoods(ctx *gin.Context, keyword string) {
	var result []entity.Goods = c.goodsService.SearchGoods(keyword)
	response := helper.SuccessResponse(0, "", result)
	ctx.JSON(http.StatusOK, response)
}
